package com.galen.manual.entity;

import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableName;
import lombok.Data;
import lombok.EqualsAndHashCode;

import java.time.LocalDateTime;

@Data
@EqualsAndHashCode(callSuper = true)
@TableName("users")
public class User extends BaseEntity {

    @TableField("openid")
    private String openid;

    @TableField("unionid")
    private String unionid;

    @TableField("username")
    private String username;

    @TableField("nickname")
    private String nickname;

    @TableField("avatar_url")
    private String avatarUrl;

    @TableField("real_name")
    private String realName;

    @TableField("phone")
    private String phone;

    @TableField("password")
    private String password;

    @TableField("sms_code")
    private String smsCode;

    @TableField("sms_code_expire_time")
    private LocalDateTime smsCodeExpireTime;

    @TableField("address")
    private String address;

    @TableField("user_level")
    private Integer userLevel; // 1:普通用户 2:高级用户 3-VIP用户

    @TableField("status")
    private Integer status; // 0:待审核 1:正常 2:冻结 3-黑名单

    @TableField("total_completed")
    private Integer totalCompleted; // 累计完成数量

    @TableField("total_earnings")
    private Double totalEarnings; // 累计收益

    @TableField("balance")
    private Double balance; // 账户余额

    // 关联查询字段（不存储在数据库中）
    @TableField(exist = false)
    private Boolean isAdmin;

    @TableField(exist = false)
    private String adminRole;

    @Override
    public void preInsert() {
        super.preInsert();
        // 用户特定的初始化逻辑
        if (this.userLevel == null) {
            this.userLevel = 1;
        }
        if (this.status == null) {
            this.status = 1;
        }
        if (this.totalCompleted == null) {
            this.totalCompleted = 0;
        }
        if (this.totalEarnings == null) {
            this.totalEarnings = 0.0;
        }
        if (this.balance == null) {
            this.balance = 0.0;
        }
    }
}